import Vue from 'vue'
import moment from 'moment'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')
const bannerState = {
  0: {
    status: 'default',
    text: '未设置'
  },
  1: {
    status: 'on',
    text: '上架'
  },
  2: {
    status: 'off',
    text: '下架'
  }
}
// order_state (integer, optional): 订单状态(10.待付款、20.待发货、30.待收货、40.收货完成) ,
// pay_state (integer, optional): 支付状态(10.待付款、20.支付成功、30.支付中、40.支付失败) ,
const payState = {
  10: {
    status: '10',
    text: '未支付'
  },
  20: {
    status: '20',
    text: '已支付'
  },
  30: {
    status: '30',
    text: '支付中'
  },
  40: {
    status: '40',
    text: '支付失败'
  }
}
const orderState = {
  10: {
    status: '10',
    text: '待付款'
  },
  20: {
    status: '20',
    text: '待发货'
  },
  30: {
    status: '30',
    text: '待收货'
  },
  40: {
    status: '40',
    text: '收货完成'
  }
}
const addressState = {
  1: {
    status: '1',
    text: '省'
  },
  2: {
    status: '2',
    text: '市'
  },
  3: {
    status: '3',
    text: '区'
  }
}
Vue.filter('NumberFormat', function (value) {
  if (!value) {
    return '0'
  }
  const intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
  return intPartFormat
})

Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})

Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})
Vue.filter('statusFilter', function (status) {
  return bannerState[status].text
})
Vue.filter('orderStatusFilter', function (status) {
  return orderState[status].text
})
Vue.filter('payStatusFilter', function (status) {
  return payState[status].text
})
Vue.filter('typeFilter', function (status) {
  return addressState[status].text
})
